﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Maticsoft.Common;
using Maticsoft.Model;
using Maticsoft.DBUtility;//Please add references

using MySql.Data;
using MySql.Data.MySqlClient;

using System.Data;

using com.qbengo.utility.nodepicker.entity;
using com.qbengo.utility.nodepicker.DAL;

namespace com.qbengo.utility.nodepicker.business
{
    class VenueBLL
    {
        VenueDao venueDao = new VenueDao();
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Venue> DataTableToList(DataTable dt)
        {
            List<Venue> modelList = new List<Venue>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Venue model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Venue();
                    if (dt.Rows[n]["venueid"] != null && dt.Rows[n]["venueid"].ToString() != "")
                    {
                        model.venueid = int.Parse(dt.Rows[n]["venueid"].ToString());
                    }
                    if (dt.Rows[n]["name"] != null && dt.Rows[n]["name"].ToString() != "")
                    {
                        model.name = dt.Rows[n]["name"].ToString();
                    }
                    if (dt.Rows[n]["desc"] != null && dt.Rows[n]["desc"].ToString() != "")
                    {
                        model.desc = dt.Rows[n]["desc"].ToString();
                    }
                    if (dt.Rows[n]["lat"] != null && dt.Rows[n]["lat"].ToString() != "")
                    {
                        //model.lat=dt.Rows[n]["lat"].ToString();
                    }
                    if (dt.Rows[n]["lng"] != null && dt.Rows[n]["lng"].ToString() != "")
                    {
                        //model.lng=dt.Rows[n]["lng"].ToString();
                    }
                    if (dt.Rows[n]["thumbnail_url"] != null && dt.Rows[n]["thumbnail_url"].ToString() != "")
                    {
                        model.thumbnail_url = dt.Rows[n]["thumbnail_url"].ToString();
                        //Console.WriteLine(dt.Rows[n]["thumbnail_url"].ToString());
                    }
                    if (dt.Rows[n]["last-updated"] != null && dt.Rows[n]["last-updated"].ToString() != "")
                    {
                        model.last_updated = DateTime.Parse(dt.Rows[n]["last-updated"].ToString().Trim());
                        //Console.WriteLine(dt.Rows[n]["last-updated"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        public List<Venue> GetVenuelList(string strWhere)
		{
			DataSet ds = this.venueDao.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
    }
}
